<?php
namespace app\index\controller;

use app\api\controller\Douyu;
use app\api\controller\Huomao;

class Index extends Base
{
    public function index($type = 'CSGO')
    {
        $list = $this->getList($type);

        $this->assign('path', request()->path());
        $this->assign('list', $list);
        return $this->fetch();
    }

    public function getList($type)
    {
        $douyu = (new Douyu())->select($type);
        $huomao = (new Huomao())->select($type);

        $list = array_merge($douyu, $huomao);

        usort($list,function ($a,$b){
            $av = $a['room_views_real'];
            $bv = $b['room_views_real'];
            if ($av == $bv){
                return 0;
            }
            return ($av > $bv) ? -1 : 1;
        });

        return $list;
    }
}
